
#ifndef __IPC_CLIENT_DUAL_CORE_FLASH_H__
#define __IPC_CLIENT_DUAL_CORE_FLASH_H__

#include "g_type.h"
#include "g_qspi.h"

/**
 * @method G_DualCore_flash_sectorerase
 * @brief  sector erase (4K)
 * @param  flash_addr:flash addr (4k Bytes align)
 * @retval ERROR,SUCCESS
 */
uint8_t G_DualCore_flash_sectorerase(uint32_t flash_addr);

/**
 * @method G_DualCore_flash_blockerase32k
 * @brief  block erase  (32K)
 * @param  flash_addr:flash addr (32k Bytes align)
 * @retval ERROR,SUCCESS
 */
uint8_t G_DualCore_flash_blockerase32k(uint32_t flash_addr);

/**
 * @method G_DualCore_flash_blockerase64k
 * @brief  block erase  (64K)
 * @param  flash_addr:flash addr (64k Bytes align)
 * @retval ERROR,SUCCESS
 */
uint8_t G_DualCore_flash_blockerase64k(uint32_t flash_addr);

/**
 * @method G_DualCore_flash_write
 * @brief  write flash
 * @param  flash_addr:flash addr (when flash_addr%256!=0,256-(flash_addr%256)+len must less than 256)
 * @param  buf
 * @param  len
 * @retval ERROR,SUCCESS
 */
uint8_t G_DualCore_flash_write(uint32_t flash_addr, uint8_t *buf, uint32_t len);

/**
 * @method G_DualCore_flash_read
 * @brief  read flash
 * @param  flash_addr:flash addr
 * @param  buf
 * @param  len
 * @retval ERROR,SUCCESS
 */
uint8_t G_DualCore_flash_read(uint32_t flash_addr, uint8_t *buf, uint32_t len);

/**
 * @method G_DualCore_flash_blank_check
 * @brief  check logical addr data is blank
 * @param  startaddr:cpu addr
 * @param  len
 * @retval TRUE:  blank
 *         FALSE: not blank
 */
G_Boolean G_DualCore_flash_blank_check(uint32_t startaddr, uint32_t len);

/**
 * @method G_DualCore_enc_write_flash
 * @brief  write data to flash with enc
 * @param  flash_addr:cpu addr (must 32 Bytes align)
 * @param  buf
 * @param  len:(must 32 Bytes align)
 * @retval ERROR,SUCCESS
 */
uint8_t G_DualCore_enc_write_flash(uint32_t flash_addr, uint8_t *buf, uint32_t len);

/**
 * @method G_DualCore_enc_read_flash
 * @brief  read flash data with enc
 * @param  flash_addr:cpu addr
 * @param  buf
 * @param  len
 * @retval ERROR,SUCCESS
 */
uint8_t G_DualCore_enc_read_flash(uint32_t flash_addr, uint8_t *buf, uint32_t len);

/**
 * @method G_DualCore_enc_read_flash_fast
  * @brief  enc read flash fast(You must sure that the read area is written by enc)
 * @param  flash_addr:cpu addr
 * @param  buf
 * @param  len
  * @return SUCCESS or ERROR
  */
uint8_t G_DualCore_enc_read_flash_fast(uint32_t flash_addr, uint8_t *buf, uint32_t len);

/**
 * @method G_DualCore_enc_erase_flash_32byte
 * @brief  erase 32 Bytes
 * @param  flash_addr : cpu addr (must 32 Bytes align)
 * @retval ERROR,SUCCESS
 */
uint8_t G_DualCore_enc_erase_flash_32byte(uint32_t flash_addr);

/**
 * @method G_DualCore_enc_erase_flash_32k
 * @brief  enc erase 32K Bytes
 * @param  flash_addr : cpu addr (must 32K Bytes align)
 * @retval ERROR,SUCCESS
 */
uint8_t G_DualCore_enc_erase_flash_32k(uint32_t flash_addr);

/**
  * @brief  enc erase flash app area
  * @param  addr:align at 32k for CPU addr
  * @param  len:erase len
  * @return ERROR,SUCCESS
  */
uint8_t G_DualCore_enc_earse_flash_app_area(uint32_t addr,uint32_t len);

/**
  * @brief  enc write download flag
  * @param  addr:BOOT_UART_DOWNLOAD_FLAG,BOOT_USB_DOWNLOAD_FLAG or BOOT_AUTO_SELECT_FLAG
  * @return ERROR,SUCCESS
  */
uint8_t G_DualCore_enc_write_download_flag(uint32_t flag);

/**
 * @method G_DualCore_enc_write_flash_bulk
 * @brief  write bulk data to flash with enc
* @param  EncBulkStruct:enc buf struct
 * @param  flash_addr:cpu addr(start addr must 32k Bytes align)
 * @param  buf
 * @param  len: Integer multiple of 32 bytes
 * @retval ERROR,SUCCESS
 */
uint8_t G_DualCore_enc_write_flash_bulk(G_ENC_BulkTypeDef *EncBulkStruct,uint32_t flash_addr, uint8_t *buf, uint32_t len);


/**
 * @method G_DualCore_read_flash_size
 * @brief  read the chip flash size
 * @param  NULL
 * @retval qspi_flash_size_enum
 */
G_qspi_flash_size_enum G_DualCore_read_flash_size(void);
#endif
